﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace _0912089
{
    public class ScaleAction : ActionHelper
    {
        private float _beginScale = 1;
        private Vector2 _originalPos;

        public float BeginScale
        {
            get { return _beginScale; }
            set { _beginScale = value; }
        }
        private float _finishScale;

        public float FinishScale
        {
            get { return _finishScale; }
            set { _finishScale = value; }
        }

        public override View View
        {
            get { return base.View; }
            set
            {
                base.View = value;
                _view = value;
                value.Action = this;
                _originalPos = _view.Position;
            }
        }

        public ScaleAction(View view, float finishScale)
        {
            if (view != null)
            {
                _view = view;
                view.Action = this;
                _originalPos = _view.Position;
            }
            _finishScale = finishScale;
        }

        public override void  excuteAction(GameTime gameTime)
        {
            if (_view.Scale == _finishScale)
            {
                _isActioning = false;
                postNotification(ActionName, "Done");
            }

            _currentTotalTime += gameTime.ElapsedGameTime.Milliseconds;

            float oldScale = _view.Scale;
            _view.Scale += _currentTotalTime / 100000;
            _view.Position -= ((_view.Size * Math.Abs(_view.Scale - oldScale)) / 2);
            if (_view.Scale > _finishScale)
                _view.Scale = _finishScale;
        }

        public override void reverse()
        {
            base.reverse();

            float temp = BeginScale;
            BeginScale = FinishScale;
            FinishScale = temp;
            _view.Position = _originalPos;
        }
    }
}
